﻿package com.mini.framework.bi.bpull.chart;

import java.util.ArrayList;
import java.util.List;

import com.mini.framework.bi.bpull.model.PieLine;

/**
 * 
 * @author lishsh.
 *
 */
public class PieLineChart {
	
	private String converType;//目前统一为‘average’
	
	private String unit;//单位.
	
	private String zhibiao;//说明.
	
	private List<String> tagn;//类型.
	
	private List<String> sum;//统计总和,有多个请用|分隔.
	
	private List<PieLine> records;//数据.

	public String getConverType() {
		return converType;
	}

	public void setConverType(String converType) {
		this.converType = converType;
	}

	public String getUnit() {
		return unit;
	}

	public void setUnit(String unit) {
		this.unit = unit;
	}

	public String getZhibiao() {
		return zhibiao;
	}

	public void setZhibiao(String zhibiao) {
		this.zhibiao = zhibiao;
	}

	public List<String> getTagn() {
		return tagn;
	}

	public void setTagn(List<String> tagn) {
		this.tagn = tagn;
	}

	

	public List<String> getSum() {
		return sum;
	}

	public void setSum(List<String> sum) {
		this.sum = sum;
	}

	public List<PieLine> getRecords() {
		return records;
	}

	public void setRecords(List<PieLine> records) {
		this.records = records;
	}
	
	public String getXml(){
		StringBuilder sb = new StringBuilder();
		sb.append("<?xml version=\"1.0\" encoding=\"gbk\"?>");
		sb.append("<data convertType=\""+this.getConverType()+"\" unit=\""+this.getUnit()+"\" zhibiao=\""+this.getZhibiao()+"\" ");
		for(int i=0;i<tagn.size();i++){
			sb.append("tag"+(i+1)+"=\""+tagn.get(i)+"\" ");
		}
		sb.append(" sum=\"");
		for(int j=0;j<sum.size();j++){
			sb.append(sum.get(j));
			if(j<sum.size()-1){
				sb.append("|");
			}
		}
		sb.append("\" >");
		for(PieLine pieLine:records){
			sb.append("<record overTag=\""+pieLine.getOverTag()+"\" xAxisTag=\""+pieLine.getXAxisTag()+"\" ");
			for(int m=0;m<pieLine.getDatan().size();m++){
				sb.append(" data"+(m+1)+"=\"");
				sb.append(pieLine.getDatan().get(m));
				sb.append("\" ");
			}
			sb.append("/>");
		}
		
		sb.append("</data>");
		return sb.toString();
	}
	
	public static void main(String arg[]){
		List<String> tags= new ArrayList<String>();
		tags.add("直达");
		tags.add("浏览量(PV)");
		tags.add("推介网站");
		List<String> sums= new ArrayList<String>();
		sums.add("100");
		sums.add("200");
		sums.add("300");
		PieLineChart chart = new PieLineChart();
		chart.setConverType("average");
		chart.setSum(sums);
		chart.setTagn(tags);
		chart.setUnit("次");
		chart.setZhibiao("PV量");
		List<PieLine> datas = new ArrayList<PieLine>();
		
		PieLine data1 = new PieLine();
		data1.setOverTag("0点");
		data1.setXAxisTag("00:00 - 00:59");
		List<String> datan1 = new ArrayList<String>();
		datan1.add("10");
		datan1.add("20");
		datan1.add("5");
		data1.setDatan(datan1);
		
		PieLine data2 = new PieLine();
		data2.setOverTag("1点");
		data2.setXAxisTag("02:00 - 02:59");
		List<String> datan2 = new ArrayList<String>();
		datan2.add("30");
		datan2.add("10");
		datan2.add("4");
		data2.setDatan(datan2);
		
		PieLine data3 = new PieLine();
		data3.setOverTag("2点");
		data3.setXAxisTag("03:00 - 03:59");
		List<String> datan3 = new ArrayList<String>();
		datan3.add("10");
		datan3.add("20");
		datan3.add("8");
		data3.setDatan(datan3);
		
		datas.add(data1);
		datas.add(data2);
		datas.add(data3);
		chart.setRecords(datas);
		System.out.println(chart.getXml());
	}
	
	

}
